package com.spancer.contentcenter.domain.entity.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author masisi
 * @date 2023/7/12 14:33
 * @Description
 */
@Data
public class ResultData<T> {

    private static final Integer RESPONSE_200 = 200;

    private Integer code;
    private String message;

    private T data;

    private Meta meta;

    public ResultData() {
    }

    public ResultData(Integer code, String message, T data, Meta meta) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.meta = meta;
    }

    public ResultData(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        data = data;
    }

    public static<T> ResultData resultOk(T data, String message){
        return new ResultData(RESPONSE_200,message,data);
    }

    public static<T> ResultData resultOk(T data){
        return new ResultData(RESPONSE_200,"操作成功",data);
    }
    public static<T> ResultData resultOkWithPage(T data,Integer pageNum,Integer pageSize,Integer total){
        Meta metaData = new Meta();
        metaData.setCurrentPage(pageNum);
        metaData.setFrom(pageNum);
        metaData.setTotal(total);
        return new ResultData(RESPONSE_200,"操作成功",data,metaData);
    }

    public static<T> ResultData resultFail(T data, String message, Integer failCode){
        return new ResultData(failCode,message,data);
    }

    public static<T> ResultData resultFail(String message, Integer failCode){
        return new ResultData(failCode,message,null);
    }
}
